<?php

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @category    EveBit_Library
 * @package     Application
 * @author      Cheng Wei <berlios.o@gmail.com>
 * @version     $$Id: View.php 229 2011-04-07 02:03:50Z cheng.wei $$
 * @copyright   Copyright (c) 2008 Evebit Inc. China (http://www.evebit.com)
 */

/**
 * @see Zend_Application_Resource_View
 */
require_once 'Zend/Application/Resource/View.php';

/**
 * Resource for settings view options and init view help
 *
 * @uses        Zend_Application_Resource_ResourceAbstract
 * 
 * @package     Application
 * @author      Cheng Wei <berlios.o@gmail.com>
 * @version     $$Id: View.php 229 2011-04-07 02:03:50Z cheng.wei $$
 */
class Evebit_Application_Resource_View extends Zend_Application_Resource_View {

	/**
	 * Defined by Zend_Application_Resource_Resource
	 *
	 * @return Zend_View
	 */
	public function init() {
		$view = $this->getView();
		
		$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
		$viewRenderer->setView($view);
		$scope = $this->getBootstrap()->getApplication()->getScope();
		$viewRenderer->setViewBasePathSpec(":moduleDir/$scope-views");
		Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
		return $view;
	}

	/**
	 * Retrieve view object
	 *
	 * @return Zend_View
	 */
	public function getView() {
		if (null === $this->_view) {
			$options = $this->getOptions();
			$this->_view = new Evebit_View($options);
			
			if (isset($options['doctype'])) {
				$this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
				if (isset($options['charset']) && $this->_view->doctype()->isHtml5()) {
					$this->_view->headMeta()->setCharset($options['charset']);
				}
			}
			if (isset($options['contentType'])) {
				$this->_view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
			}
		}
		return $this->_view;
	}
}
